<template>
  <div>
    <el-dialog
      :title="title"
      :visible="dialogVisible"
      :show-close="false"
      width="800px"
    >
      <el-form
        ref="roleDialog"
        :model="row"
        :rules="rules"
        label-width="120px"
      >
        <el-form-item
          label="角色名称:"
          prop="gname"
          style="width: 350px;"
        >
          <el-input
            v-model="row.gname"
            size="medium"
            placeholder="请输入角色名称"
          />
        </el-form-item>
        <!-- <el-form-item label="角色权限:" prop="role">
          <el-select v-model="row.cartype1" placeholder="请选择" clearable>
            <el-option
              v-for="item in CarTypeList()"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item> -->
      </el-form>
      <span slot="footer">
        <el-button
          @click="handleCancel"
        >
          取 消
        </el-button>
        <el-button
          type="primary"
          @click="handleConfirm"
        >
          确 定
        </el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import mixin from '@/mixin/mixin'

export default {
  name: 'RoleDialog',
  mixins: [mixin],
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    row: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      title: '',
      rules: {
        gname: [
          {
            required: true,
            message: '角色名称不能为空',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  updated() {
    if (this.row.role) {
      this.title = '编辑角色'
    } else {
      this.title = '新增角色'
    }
  },
  methods: {
    handleCancel() {
      this.$emit('cancel-dialog')
      this.$refs.roleDialog.resetFields()
    },
    handleConfirm() {
      this.$refs.roleDialog.validate((valid) => {
        if (valid) {
          this.$emit('confirm-dialog', {
            // dialog: this.$refs.garageDialog,
            role: this.row.role,
            gname: this.row.gname
            // role: this.row.role
          })
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style>
</style>
